<div class="layui-card">
  <form class="layui-form" lay-filter="add-goods-form">
    <blockquote class="layui-elem-quote">非偏远地区运费</blockquote>
    <div class="freight-top">当前设置：运费 ¥ <span id="unfar_express_fee"></span> 满 ¥ <span id="unfar_order_price"></span> 免运费</div>
    <div class="layui-field-box">
        <div class="layui-form-item">
            <label class="layui-form-label">运费：</label>
            <div class="layui-input-inline">
            <span class="sp3">￥</span>	
            <input name="unfar_express_fee" placeholder="" autocomplete="off" class="layui-input int1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">买书订单满多少可免运费：</label>
            <div class="layui-input-inline">
            <span class="sp3">￥</span>	
            <input name="unfar_order_price" placeholder="" autocomplete="off" class="layui-input int1">
            </div>
        </div>
    </div>
    <blockquote class="layui-elem-quote">偏远地区运费</blockquote>
    <div class="freight-top">当前设置：运费 ¥ <span id="far_express_fee"></span> 满 ¥ <span id="far_order_price"></span> 免运费</div>
    <div class="layui-field-box">
        <div class="layui-form-item">
            <label class="layui-form-label">运费：</label>
            <div class="layui-input-inline">
            <span class="sp3">￥</span>	
            <input name="far_express_fee" placeholder="" autocomplete="off" class="layui-input int1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">买书订单满多少可免运费：</label>
            <div class="layui-input-inline">
            <span class="sp3">￥</span>	
            <input name="far_order_price" placeholder="" autocomplete="off" class="layui-input int1">
            </div>
        </div>
        <p style="color: red;">偏远地区包括：西藏、新疆、青海、内蒙古、宁夏、甘肃</p>
	    <div class="layui-form-item" style="text-align: center">
	        <div class="layui-input-block">
	            <button class="layui-btn" lay-submit lay-filter="formDemo2">保存</button>
	        </div>
	    </div>
    </div>
  </form>

<script>
    //Demo
  layui.use(['form', 'upload'], function(){
    var form = layui.form;
    var $ = layui.$;
    init();
    function init() {
	   	  $.ajax({
				    type: "GET",
				    dataType: "json",
				    url: "https://bookshop.dingdangtoy.com/api/admin/express_fee_config/show",
				    data: {},
				    headers: { //通过 request 头传递
		              'access-token': layui.data('layuiAdmin').access_token
		            },
					success: function(data){
	                  console.log(data)
					  $('#unfar_express_fee').text(data.data.unfar_express_fee)
	                  $('#unfar_order_price').text(data.data.unfar_order_price)
	                  $('#far_express_fee').text(data.data.far_express_fee)
	                  $('#far_order_price').text(data.data.far_order_price)
					    
					},
					error: function(msg){
					  console.log(msg)
					}
				});      	
    }   
	  // 监听编辑提交
	  form.on('submit(formDemo2)', function(data){	
        //执行 Ajax 后重载
   	  $.ajax({
			    type: "POST",
			    dataType: "json",
			    url: "https://bookshop.dingdangtoy.com/api/admin/express_fee_config/store",
			    data: {
			    	far_express_fee:data.field.far_express_fee,
			    	far_order_price:data.field.far_order_price,
			    	unfar_express_fee:data.field.unfar_express_fee,
				    unfar_order_price:data.field.unfar_order_price	
			    },
			    headers: { //通过 request 头传递
	              'access-token': layui.data('layuiAdmin').access_token
	            },
				success: function(data){
				  if(data.code == 0){
				  	init();
				  	layer.msg('操作成功');
				  } else {
				  	layer.msg(data.message);
				  }
				    
				},
				error: function(msg){
				  console.log(msg)
				}
			});  

	    return false;
	  });
	  
  });
</script>
<style>
    .layui-form-label {text-align: center; width: 170px;}
    .freight-top{
    	height: 60px;
    	line-height: 60px;
    	padding: 0 106px;
    	margin-bottom: 20px;
    	font-size: 18px;
    	border-bottom: 1px solid #000000;
    }
    .int1{position: relative;padding-left: 30px;}
    .sp3{position: absolute;left: 10px;top: 10px;z-index: 10;color: #999;}
</style>